home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 5 / BBS in a Box -Volume V (BBS in a Box) (April 1992).iso / Files / Tele / S / Sysop Module Source 1.0.cpt / Sysop Module code / Sysop Module Main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-01  |  24.0 KB  |  669 lines  |  [TEXT/KAHL]

  1. /*
  2.  *  Sysop Module Main.c
  3.  *
  4.  *    This program source code and it's compiled version is
  5.  *  Copyright (c) 1991 N. Hawthorn.
  6.  *  This program source code and it's compiled version IS NOT IN THE
  7.  *  PUBLIC DOMAIN ! Please read the "COPYRIGHT NOTICE / NH" file for details
  8.  *  regarding use of this program source code and it's compiled version.
  9.  *
  10.  *  This module's name is "sysop", it's type is "MOD1", use a resource mover
  11.  *  to assign a new number to it, that's why we name our modules !
  12.  *
  13.  *  This is where it all starts...
  14.  *
  15.  */
  16.  
  17. #define INMAIN
  18.  
  19. #include <SetUpA4.h>
  20. #include "MUBBS Module.h"
  21.  
  22. struct PPP {
  23.             char passstring[260]; /* the string to pass to the module */
  24.             int field;   /* the field to get */
  25.             int uerror;   /* any errors found ? */
  26.             };
  27.  
  28.  
  29. /* my globals for this file */
  30.  
  31.  
  32.  
  33. pascal void main (mode1,G1,P) /* called from the main routines, and what mode to be in */
  34. int mode1;
  35. struct GS *G1; /* we point to the "global" struct in the Main Module here */
  36. Ptr P; /* we ignore this pointer, we do not use it at all */
  37. {
  38. Handle temph;
  39. float version = 0.5; /* what version of MUBBS you are compatable with IE: .5 and above */
  40. RememberA0(); SetUpA4(); /* This sets up the A4 register to access our globals */
  41. asm { _RecoverHandle }; asm {move.l a0,temph}; HLock(temph); /* locks our module, do this ! */
  42.  
  43. G=G1; /* This MUST be the first thing you do in main only, it sets up the struct globals */
  44. mode[u]=mode1; /* set up our mode so that you can read it anywhere */
  45.  
  46. switch (mode[u]) { /* any un-handled modes return error from this module */
  47.     case 2:
  48.         doit();
  49.         G->moduleresult=0;
  50.         break;
  51.     case 98:
  52.         versionck(version); /* just return after this call, don't modify anything */
  53.         break;        
  54.     case 0:
  55.         strcpy (G->programmer,"N Hawthorn"); /* show the programmer's name up to 20 chars*/
  56.         G->moduleresult=0; /* this was also a init call if we need close call put 99 here */
  57.         break;
  58.     default:
  59.         G->moduleresult=1; /* return bad code */
  60.     };
  61.  
  62. HUnlock(temph); /* unlocks this module, do this ! */
  63. RestoreA4(); /* call this when you are all done */
  64. }
  65.  
  66.  
  67. doit()
  68. {
  69. int i;
  70. char temp[128], temp2[128];
  71.  
  72. if (!G->online[u]) goto done; /* do this check so we can log out if hang up */
  73.  
  74. loguser("SYSOP MENU !!"); /* this tells where you are for remote sysop, or writes to log file */
  75.  
  76. /* you print the following so that the sysop can monitor use on the mac screen */
  77.  
  78. print("\nC> SYSOP Menu, user is :%s at %s baud on line #%d with access :%d ",G->username[u],G->userbaud[u],(u+1),G->userpriv[u]);
  79.  
  80. if (G->userpriv[u] <19) goto done;
  81.  
  82. loop:
  83. send("]]  *** SYSOP ***]]");
  84. if (!(cmd1(">> Operations, Readlogs, Who's on, Quit :"))) goto byebye; /* timeout */
  85. send (G->CR[u]);
  86. switch (G->input[u]) {
  87.     case 'O':
  88.         operations();
  89.         break;
  90.     case 'R':
  91.         goto loop2;
  92.         break;
  93.     case 'W':
  94.         for (i = 0; i < G->users; i++) {
  95.             if (G->online[i]) {
  96.                 send("]Line %d \"%s\" at %s baud with access :%d ",(i+1),G->username[i],G->userbaud[i],G->userpriv[i]);
  97.                 send("]       Location :%s ",G->userlocation[i]);
  98.                 }
  99.             else send("]Line %d INACTIVE]",(i+1));
  100.             }
  101.         if (!G->online[u]) goto byebye; /* log out */
  102.         send ("]---------------------------------------------------------------------------]");
  103.         break;
  104.     case 'Q':        /* Quit */
  105.         return;
  106.         break;
  107.     }
  108. if (!G->online[u]) goto byebye; /* log out */
  109. goto loop;
  110.  
  111. loop2:
  112. send("]]  *** Read Log Files ***]]");
  113. if (!(cmd1(">> Downloadlog, Loginuserlog, Systemlog, Uploadlog, Quit :"))) goto byebye; /* timeout */
  114. send (G->CR[u]);
  115. send (G->CR[u]); /* these files don't have a CR at start */
  116. switch (G->input[u]) {
  117.     case 'D':
  118.         backwardsfile (":logs:downloadlog");
  119.         if (!G->online[u]) goto byebye; /* log out */
  120.         send ("]---------------------------------------------------------------------------]");
  121.         break;
  122.     case 'L':
  123.         backwardsfile (":logs:userlog");
  124.         if (!G->online[u]) goto byebye; /* log out */
  125.         send ("]---------------------------------------------------------------------------]");
  126.         break;
  127.     case 'S':
  128.         backwardsfile (":logs:systemlog");
  129.         if (!G->online[u]) goto byebye; /* log out */
  130.         send ("]---------------------------------------------------------------------------]");
  131.         break;
  132.     case 'U':
  133.         backwardsfile (":logs:uploadlog");
  134.         if (!G->online[u]) goto byebye; /* log out */
  135.         send ("]---------------------------------------------------------------------------]");
  136.         break;
  137.     case 'Q':        /* Quit */
  138.         goto loop;
  139.         break;
  140.     }
  141. if (!G->online[u]) goto byebye; /* log out */
  142. goto loop2;
  143.  
  144.  
  145. byebye:
  146. G->online[u]=FALSE; /* show we timed out */
  147. done:
  148. return;
  149. }
  150.  
  151.  
  152. operations()
  153. {
  154. char datetime[25],tempfile[25], temp[128], temp2[128];
  155. int tries;
  156. FILE *stream;
  157.  
  158. if (getpass()) goto okpass;
  159.  
  160. getdatetime(datetime); /* gets the date & time */
  161. tries = 0;
  162. bsylp:
  163. if ((stream = fopen(":logs:userlog", "a")) == NULL) {    /* add to the file */
  164.     if (++tries < 10) {
  165.         send("PLEASE STANDBY]");
  166.         wait(1); /* wait just a bit */
  167.         goto bsylp;
  168.         }
  169.     send("FILE ERROR - Can't open the userlog file!]");
  170.     fclose(stream);
  171.     }
  172. else {
  173.     if (fprintf(stream, "** SYSOP ** ACCESS DENIED !! %s %s %s LINE=%d\n", datetime, G->username[u], G->userbaud[u], (u+1)) < 0) {
  174.         send("FILE ERROR %d - userlog file file has problem writing]");
  175.         fclose(stream);
  176.         }
  177.     }
  178. fclose(stream);
  179. print("** SYSOP ** ACCESS DENIED TO: %s %s LINE=%d\n", G->username[u], G->userbaud[u], (u+1));
  180. send("]]ACCESS DENIED..]]");
  181. G->online[u]=FALSE;
  182. return;
  183.  
  184.  
  185. okpass:
  186. send("]]  *** Heavy Sysop Stuff  BE CAREFUL HERE !!  ***]]");
  187. if (!(cmd1(">> Edit user, User list, Verify user list, Quit :"))) goto byebye; /* timeout */
  188. send (G->CR[u]);
  189. switch (G->input[u]) {
  190.     case 'E':
  191.         edituserinfo();
  192.         break;
  193.     case 'U':
  194.         listusers();
  195.         break;
  196.     case 'V':
  197.         checkuserlist();
  198.         break;
  199.     case 'Q':        /* Quit */
  200.         return;
  201.         break;
  202.     }
  203. if (!G->online[u]) goto byebye; /* log out */
  204. goto okpass;
  205.  
  206.  
  207. byebye:
  208. G->online[u]=FALSE; /* show we timed out */
  209. return;
  210. }
  211.  
  212. getpass()
  213. {
  214. char temp[40];
  215. char password[40];
  216. FILE *stream;
  217. if ((stream = fopen(":bbssupport:sysopstuff", "r")) == NULL) {
  218.     send("] ERROR ! Cannot open 'sysopstuff' file !!]"); 
  219.     return FALSE;
  220.     }
  221. else {
  222.     fscanf(stream,"%30[^\n]\n",password);
  223.     fclose(stream);
  224.     }
  225.  
  226. strtoupper(password); /* uppercase the password */
  227.  
  228. send("]Sysop Password :");
  229. passportsin(temp, 30);
  230. strtoupper(temp); /* uppercase the password */
  231. send(G->CR[u]);
  232. if (! G->online[u]) return FALSE; /* returns online for a time out */
  233. if (strcmp(password,temp) == 0) {
  234.     return TRUE;
  235.     }
  236. return FALSE;
  237. }
  238.  
  239.  
  240.  
  241. listusers()
  242. {
  243. char tempname[maxnamelength];
  244. char tempalias[maxnamelength];
  245. char temppass[maxnamelength];
  246. char tempaddress[maxnamelength];
  247. char tempcity[maxnamelength];
  248. char tempphone[maxnamelength];
  249. char tempmachine[maxnamelength];
  250. char tempfirst[maxnamelength];
  251. char templevel[maxnamelength];
  252. char tempsettings[maxnamelength];
  253. char tempbirth[maxnamelength];
  254. char tempextras1[maxnamelength];
  255. char tempextras2[maxnamelength];
  256. char tempmins[maxnamelength];
  257. char temptimes[maxnamelength];
  258. char templast[maxnamelength];
  259. char tempupdown[maxnamelength];
  260. char tempcomments[260];
  261. char tchar[260], temp[65];
  262. int lnum,tempint,got,chars;
  263. long int pos;
  264. FILE *stream;
  265.  
  266. send("]User List Printout :]]");
  267.  
  268. if ((stream = fopen(":user:userlist", "r")) == NULL) {
  269.     print("C> FILE ERROR - cannot open user:userlist\n");
  270.     send("]FILE ERROR - Can't open the user list file !]");
  271.     goto endthis;
  272.     }
  273.  
  274. more:
  275.     pos = ftell(stream); /* get the current file position */
  276.     fgets(tchar,33,stream); if (feof(stream)) goto goteof; sscanf(tchar,"%30[^~]",tempname);  /* the user's name */
  277.     fgets(tchar,33,stream); if (feof(stream)) goto goteof; sscanf(tchar,"%30[^~]",tempalias); if (feof(stream)) goto goteof; /* the user's alias */
  278.     fgets(tchar,33,stream); if (feof(stream)) goto goteof; sscanf(tchar,"%30[^~]",temppass); if (feof(stream)) goto goteof; /* the user's password */
  279.     fgets(tchar,33,stream); if (feof(stream)) goto goteof; sscanf(tchar,"%30[^~]",templevel); if (feof(stream)) goto goteof; /* the user's access level */
  280.     fgets(tchar,33,stream); if (feof(stream)) goto goteof; sscanf(tchar,"%30[^~]",tempaddress); if (feof(stream)) goto goteof; /* the user's address */
  281.     fgets(tchar,33,stream); if (feof(stream)) goto goteof; sscanf(tchar,"%30[^~]",tempcity); if (feof(stream)) goto goteof; /* the user's city and state */
  282.     fgets(tchar,33,stream); if (feof(stream)) goto goteof; sscanf(tchar,"%30[^~]",tempphone); if (feof(stream)) goto goteof; /* the user's phone number */
  283.     fgets(tchar,33,stream); if (feof(stream)) goto goteof; sscanf(tchar,"%30[^~]",tempmachine); if (feof(stream)) goto goteof; /* the user's machine */
  284.     fgets(tchar,33,stream); if (feof(stream)) goto goteof; sscanf(tchar,"%30[^~]",tempfirst); if (feof(stream)) goto goteof; /* date first logged in */
  285.     fgets(tchar,33,stream); if (feof(stream)) goto goteof; sscanf(tchar,"%30[^~]",tempsettings); if (feof(stream)) goto goteof; /* user's settings */
  286.     fgets(tchar,33,stream); if (feof(stream)) goto goteof; sscanf(tchar,"%30[^~]",tempbirth); if (feof(stream)) goto goteof; /* birth info */
  287.     fgets(tchar,33,stream); if (feof(stream)) goto goteof; sscanf(tchar,"%30[^~]",tempextras1); if (feof(stream)) goto goteof; /* any other info for later use */
  288.     fgets(tchar,33,stream); if (feof(stream)) goto goteof; sscanf(tchar,"%30[^~]",tempextras2); if (feof(stream)) goto goteof; /* any other info for later use */
  289.     fgets(tchar,33,stream); if (feof(stream)) goto goteof; sscanf(tchar,"%30[^~]",temptimes); if (feof(stream)) goto goteof; /* the number of times this user has been on */
  290.     fgets(tchar,33,stream); if (feof(stream)) goto goteof; sscanf(tchar,"%30[^~]",templast); if (feof(stream)) goto goteof; /* the last date user was on */
  291.     fgets(tchar,33,stream); if (feof(stream)) goto goteof; sscanf(tchar,"%30[^~]",tempmins); if (feof(stream)) goto goteof; /* the time the user was on last time */
  292.     fgets(tchar,33,stream); if (feof(stream)) goto goteof; sscanf(tchar,"%30[^~]",tempupdown); if (feof(stream)) goto goteof; /* uploads/downloads */
  293.     fgets(tchar,258,stream); sscanf(tchar,"%255[^~]",tempcomments);  /* comments field for the user */
  294.  
  295. chars = (ftell(stream) - pos);
  296. if(chars != 801) { /* (entire record should be 801 chars)*/
  297.     pos = ftell(stream);
  298.     send("]]ERROR on record position %ld, got %d chars, should be 801 !]",pos,chars);
  299.     goto endthis;
  300.     }
  301.  
  302. send("%s]",tempname);
  303. tempint=strtoint(templevel); /* check to see if we have privs to read this */
  304. if (G->userpriv[u] < tempint) {
  305.     send("]You do not have privledges to access this record!]");
  306.     goto more;
  307.     }
  308. send("%s]",tempaddress);
  309. send("%s]",tempcity);
  310. send("%s]",tempphone);
  311. removespaces(templevel); /* takes out trailing spaces */
  312. removespaces(tempmachine); /* takes out trailing spaces */
  313. removespaces(templast); /* takes out trailing spaces */
  314. removespaces(temptimes); /* takes out trailing spaces */
  315. removespaces(tempcomments); /* takes out trailing spaces */
  316. send("Level %s, mach. %s, Calls %s, Last %s]Comm: %s]]",templevel,tempmachine,temptimes,templast,tempcomments);
  317. if (!G->cancel[u]) goto more;
  318.  
  319. goteof:
  320. send("]--EOF--]");
  321. fclose(stream);
  322. endthis:
  323. return;
  324. }
  325.  
  326.  
  327.  
  328. edituserinfo()
  329. {
  330. char tempname[maxnamelength];
  331. char tempalias[maxnamelength];
  332. char temppass[maxnamelength];
  333. char tempaddress[maxnamelength];
  334. char tempcity[maxnamelength];
  335. char tempphone[maxnamelength];
  336. char tempmachine[maxnamelength];
  337. char tempfirst[maxnamelength];
  338. char templevel[maxnamelength];
  339. char tempsettings[maxnamelength];
  340. char tempbirth[maxnamelength];
  341. char tempextras1[maxnamelength];
  342. char tempextras2[maxnamelength];
  343. char tempmins[maxnamelength];
  344. char temptimes[maxnamelength];
  345. char templast[maxnamelength];
  346. char tempupdown[maxnamelength];
  347. char tempcomments[260];
  348. char tchar[260], ans[33], temp[65];
  349. int lnum,tempint,chars;
  350. long int pos;
  351. struct PPP P; /* make the struct here ! */
  352. FILE *stream;
  353.  
  354. backname:
  355. send("]Enter the user's name or RETURN to quit :");
  356. portsin(ans,30);
  357. send(G->CR[u]);
  358. if (ans[0] == '\0') return;
  359.  
  360. if ( ! getuserinfo(ans)) {    ; /* see if this user exists */
  361.     send ("]]Sorry, that name doesn't exist. Please select another...]");
  362.     goto backname;
  363.     }
  364. showloop:
  365. if ((stream = fopen(":user:userlist", "r")) == NULL) {
  366.     print("C> FILE ERROR - cannot open :user:userlist\n");
  367.     send("]FILE ERROR - Can't open the user list file !]");
  368.     goto endthis1;
  369.     }
  370.  
  371. /* start at the users file position */
  372. if(fseek(stream,G->userfilepos[u],0) != 0) print("\nC> Fseek failed ");
  373.     pos = ftell(stream); /* get the current file position */
  374.     fgets(tchar,33,stream); if (feof(stream)) goto goteof; sscanf(tchar,"%30[^~]",tempname);  /* the user's name */
  375.     fgets(tchar,33,stream); if (feof(stream)) goto goteof; sscanf(tchar,"%30[^~]",tempalias); if (feof(stream)) goto goteof; /* the user's alias */
  376.     fgets(tchar,33,stream); if (feof(stream)) goto goteof; sscanf(tchar,"%30[^~]",temppass); if (feof(stream)) goto goteof; /* the user's password */
  377.     fgets(tchar,33,stream); if (feof(stream)) goto goteof; sscanf(tchar,"%30[^~]",templevel); if (feof(stream)) goto goteof; /* the user's access level */
  378.     fgets(tchar,33,stream); if (feof(stream)) goto goteof; sscanf(tchar,"%30[^~]",tempaddress); if (feof(stream)) goto goteof; /* the user's address */
  379.     fgets(tchar,33,stream); if (feof(stream)) goto goteof; sscanf(tchar,"%30[^~]",tempcity); if (feof(stream)) goto goteof; /* the user's city and state */
  380.     fgets(tchar,33,stream); if (feof(stream)) goto goteof; sscanf(tchar,"%30[^~]",tempphone); if (feof(stream)) goto goteof; /* the user's phone number */
  381.     fgets(tchar,33,stream); if (feof(stream)) goto goteof; sscanf(tchar,"%30[^~]",tempmachine); if (feof(stream)) goto goteof; /* the user's machine */
  382.     fgets(tchar,33,stream); if (feof(stream)) goto goteof; sscanf(tchar,"%30[^~]",tempfirst); if (feof(stream)) goto goteof; /* date first logged in */
  383.     fgets(tchar,33,stream); if (feof(stream)) goto goteof; sscanf(tchar,"%30[^~]",tempsettings); if (feof(stream)) goto goteof; /* user's settings */
  384.     fgets(tchar,33,stream); if (feof(stream)) goto goteof; sscanf(tchar,"%30[^~]",tempbirth); if (feof(stream)) goto goteof; /* birth info */
  385.     fgets(tchar,33,stream); if (feof(stream)) goto goteof; sscanf(tchar,"%30[^~]",tempextras1); if (feof(stream)) goto goteof; /* any other info for later use */
  386.     fgets(tchar,33,stream); if (feof(stream)) goto goteof; sscanf(tchar,"%30[^~]",tempextras2); if (feof(stream)) goto goteof; /* any other info for later use */
  387.     fgets(tchar,33,stream); if (feof(stream)) goto goteof; sscanf(tchar,"%30[^~]",temptimes); if (feof(stream)) goto goteof; /* the number of times this user has been on */
  388.     fgets(tchar,33,stream); if (feof(stream)) goto goteof; sscanf(tchar,"%30[^~]",templast); if (feof(stream)) goto goteof; /* the last date user was on */
  389.     fgets(tchar,33,stream); if (feof(stream)) goto goteof; sscanf(tchar,"%30[^~]",tempmins); if (feof(stream)) goto goteof; /* the time the user was on last time */
  390.     fgets(tchar,33,stream); if (feof(stream)) goto goteof; sscanf(tchar,"%30[^~]",tempupdown); if (feof(stream)) goto goteof; /* uploads/downloads */
  391.     fgets(tchar,258,stream); sscanf(tchar,"%255[^~]",tempcomments);  /* comments field for the user */
  392.  
  393. chars = (ftell(stream) - pos);
  394. if(chars != 801) { /* (entire record should be 801 chars)*/
  395.     pos = ftell(stream);
  396.     send("]]ERROR on record position %ld, got %d chars, should be 801 !]",pos,chars);
  397.     goto endthis;
  398.     }
  399.  
  400. tempint=strtoint(templevel); /* check to see if we have privs to read this */
  401. if (G->userpriv[u] < tempint) {
  402.     send("]You do not have privledges to access this record !]");
  403.     goto endthis;
  404.     }
  405. send("]User info fields:]");
  406. send(" 1. Name     = %s]",tempname);
  407. send(" 2. Alias    = %s]",tempalias);
  408. send(" 3. Pass     = %s]",temppass);
  409. send(" 4. Level    = %s]",templevel);
  410. send(" 5. Address  = %s]",tempaddress);
  411. send(" 6. City     = %s]",tempcity);
  412. send(" 7. Phone    = %s]",tempphone);
  413. send(" 8. Machine  = %s]",tempmachine);
  414. send(" 9. First on = %s]",tempfirst);
  415. send("10. Settings = %s]",tempsettings);
  416. send("11. Birth    = %s]",tempbirth);
  417. send("12. Allmsg   = %s]",tempextras1);
  418. send("13. Extras   = %s]",tempextras2);
  419. send("14. Times on = %s]",temptimes);
  420. send("15. Last  on = %s]",templast);
  421. send("16. Mins on  = %s]",tempmins);
  422. send("17. Up/Down  = %s]",tempupdown);
  423. removespaces(tempcomments); /* takes out trailing spaces */
  424. send("18. Comments =]%s]",tempcomments);
  425.  
  426. send(G->CR[u]);
  427. send("Enter field number to edit or RETURN to exit :");
  428. portsin(ans, 2);
  429. send(G->CR[u]);
  430. if (ans[0] == '\0') goto endthis;
  431. lnum = strtoint(ans);
  432. if (lnum <= 0) goto endthis;
  433. if (lnum > 18) goto endthis;
  434. send("]Enter new text or RETURN to quit:");
  435. if (lnum == 18) {portsin(ans,255);}
  436. else portsin(ans,30);
  437. send(G->CR[u]);
  438. if (ans[0] == '\0') goto endthis;
  439. fclose(stream);
  440. if (lnum == 18) {sprintf(P.passstring,"%-255s~\n",ans);}
  441. else sprintf(P.passstring,"%-30s~\n",ans);
  442. P.field = lnum; /* Replace user's field */
  443. module (3,"putuserfield",&P); /* int mode & module's name & pointer to the P struct */
  444. if ( ! P.uerror){ 
  445.     send("]ERROR TRYING TO UPDATE USER FIELD %d]",lnum);
  446.     }
  447. else send("]User's field #%d has been updated..]",lnum);
  448. goto showloop;
  449.  
  450. goteof:
  451. endthis:
  452. fclose(stream);
  453. endthis1:
  454. getuserinfo(G->username[u]); /* set my file position back */
  455. }
  456.  
  457.  
  458. getuserinfo(gettemp)
  459. char *gettemp;
  460. {
  461. char tempname[maxnamelength];
  462. char temp1[maxnamelength],temp2[maxnamelength];
  463. char tchar[260];
  464. int count;
  465. long pos;
  466. FILE *stream;
  467.  
  468. if ((stream = fopen(":user:userlist", "r")) == NULL) {
  469.     print("C> FILE ERROR - cannot open :bbsuser:userlist\n");
  470.     send("]FILE ERROR - Can't open the user list file !]");
  471.     return FALSE;
  472.     }
  473. count = 0;
  474. pos=0;
  475. sprintf(temp2,"%-30s",gettemp); /* Prepare the user name for compare */
  476. strtoupper(temp2);
  477.  
  478. while (TRUE){
  479.  
  480.     if(fseek(stream,pos,0) != 0) print("C> Fseek failed\n"); /* go to the record */
  481.     fscanf(stream,"%30[^~]",tempname); if (feof(stream)) goto goteof;  /* the user's name */
  482.     strcpy(temp1,tempname); /* save the actual name for later */
  483.     strtoupper(tempname);
  484.     if (strcmp(tempname,temp2) == 0) {
  485.         G->userfilepos[u]=pos; /* save the file position for later reference */
  486.         removespaces(temp1); /* takes out trailing spaces */
  487.         strcpy(gettemp,temp1); /* make their name correct */
  488.         fclose(stream);
  489.         return TRUE;
  490.         }
  491.     otheruser(FALSE); /* do switch */
  492.     if ((++count % 10) == 0) {sendnc (".");} /* show dots */
  493.     pos=pos+801; /* move up a record */
  494.     }
  495. goteof:
  496. fclose(stream);
  497. return FALSE;  /* user was not found */
  498.  
  499. }
  500.  
  501.  
  502.  
  503. checkuserlist() /* goes through the list and checks for correct spacing of data */
  504. {
  505. char tempname[maxnamelength];
  506. char tempalias[maxnamelength];
  507. char temppass[maxnamelength];
  508. char tempaddress[maxnamelength];
  509. char tempcity[maxnamelength];
  510. char tempphone[maxnamelength];
  511. char tempmachine[maxnamelength];
  512. char tempfirst[maxnamelength];
  513. char templevel[maxnamelength];
  514. char tempsettings[maxnamelength];
  515. char tempbirth[maxnamelength];
  516. char tempextras1[maxnamelength];
  517. char tempextras2[maxnamelength];
  518. char tempmins[maxnamelength];
  519. char temptimes[maxnamelength];
  520. char templast[maxnamelength];
  521. char tempupdown[maxnamelength];
  522. char tempcomments[260];
  523. char temp1[maxnamelength], temp2[maxnamelength];
  524. char tchar[260], temp[65];
  525. int count,got,chars;
  526. long pos;
  527. FILE *stream;
  528.  
  529. send("]Checking userlist by reading all records and checking for extra or missing chars]");
  530.  
  531. if ((stream = fopen(":user:userlist", "r")) == NULL) {
  532.     print("C> FILE ERROR - cannot open :user:userlist\n");
  533.     send("]FILE ERROR - Can't open the user list file !]");
  534.     return (FALSE);
  535.     }
  536. count = 0;
  537.  
  538. while (TRUE){
  539.  
  540.     pos = ftell(stream); /* get the current file position */
  541.     fgets(tchar,33,stream); if (feof(stream)) goto goteof; sscanf(tchar,"%30[^~]",tempname);  /* the user's name */
  542.     fgets(tchar,33,stream); if (feof(stream)) goto goteof; sscanf(tchar,"%30[^~]",tempalias); if (feof(stream)) goto goteof; /* the user's alias */
  543.     fgets(tchar,33,stream); if (feof(stream)) goto goteof; sscanf(tchar,"%30[^~]",temppass); if (feof(stream)) goto goteof; /* the user's password */
  544.     fgets(tchar,33,stream); if (feof(stream)) goto goteof; sscanf(tchar,"%30[^~]",templevel); if (feof(stream)) goto goteof; /* the user's access level */
  545.     fgets(tchar,33,stream); if (feof(stream)) goto goteof; sscanf(tchar,"%30[^~]",tempaddress); if (feof(stream)) goto goteof; /* the user's address */
  546.     fgets(tchar,33,stream); if (feof(stream)) goto goteof; sscanf(tchar,"%30[^~]",tempcity); if (feof(stream)) goto goteof; /* the user's city and state */
  547.     fgets(tchar,33,stream); if (feof(stream)) goto goteof; sscanf(tchar,"%30[^~]",tempphone); if (feof(stream)) goto goteof; /* the user's phone number */
  548.     fgets(tchar,33,stream); if (feof(stream)) goto goteof; sscanf(tchar,"%30[^~]",tempmachine); if (feof(stream)) goto goteof; /* the user's machine */
  549.     fgets(tchar,33,stream); if (feof(stream)) goto goteof; sscanf(tchar,"%30[^~]",tempfirst); if (feof(stream)) goto goteof; /* date first logged in */
  550.     fgets(tchar,33,stream); if (feof(stream)) goto goteof; sscanf(tchar,"%30[^~]",tempsettings); if (feof(stream)) goto goteof; /* user's settings */
  551.     fgets(tchar,33,stream); if (feof(stream)) goto goteof; sscanf(tchar,"%30[^~]",tempbirth); if (feof(stream)) goto goteof; /* birth info */
  552.     fgets(tchar,33,stream); if (feof(stream)) goto goteof; sscanf(tchar,"%30[^~]",tempextras1); if (feof(stream)) goto goteof; /* any other info for later use */
  553.     fgets(tchar,33,stream); if (feof(stream)) goto goteof; sscanf(tchar,"%30[^~]",tempextras2); if (feof(stream)) goto goteof; /* any other info for later use */
  554.     fgets(tchar,33,stream); if (feof(stream)) goto goteof; sscanf(tchar,"%30[^~]",temptimes); if (feof(stream)) goto goteof; /* the number of times this user has been on */
  555.     fgets(tchar,33,stream); if (feof(stream)) goto goteof; sscanf(tchar,"%30[^~]",templast); if (feof(stream)) goto goteof; /* the last date user was on */
  556.     fgets(tchar,33,stream); if (feof(stream)) goto goteof; sscanf(tchar,"%30[^~]",tempmins); if (feof(stream)) goto goteof; /* the time the user was on last time */
  557.     fgets(tchar,33,stream); if (feof(stream)) goto goteof; sscanf(tchar,"%30[^~]",tempupdown); if (feof(stream)) goto goteof; /* uploads/downloads */
  558.     fgets(tchar,258,stream); sscanf(tchar,"%255[^~]",tempcomments);  /* comments field for the user */
  559.  
  560.  
  561. chars = (ftell(stream) - pos);
  562. if(chars != 801) { /* (entire record should be 801 chars)*/
  563.     pos = ftell(stream);
  564.     send("]]ERROR in userlist at position %ld ! Check it out !]",pos);
  565.     print("\nC> ERROR on record position %ld, got %d chars, should be 801 !\n",pos,chars);
  566.     fclose(stream);
  567.     return FALSE;
  568.     }
  569.     otheruser(FALSE); /* do switch */
  570.     if ((++count % 10) == 0) {sendnc (".");} /* show dots */
  571.     }
  572. goteof:
  573. fclose(stream);
  574. send("]User list checks out OK !]");
  575. return TRUE;  /* records are OK */
  576. }
  577.  
  578.  
  579.  
  580.  
  581. backwardsfile(thefile)
  582. char *thefile;
  583. {
  584. char temp[520],output[520],nexttime[520];
  585. long int seek,startfile,endfile, strstart, strend, got,toget;
  586. int endoffile,count,i,err1,a;
  587. FILE *stream;
  588.  
  589. if ((stream = fopen(thefile, "r")) == NULL) {
  590.     print("C> FILE ERROR - cannot open \"%s\"\n",thefile);
  591.     send("]FILE ERROR - Cannot open \"%s\"]",thefile);
  592.     return;
  593.     }
  594.  
  595. strcpy (nexttime,""); /* blank this out for now */
  596.  
  597. startfile=ftell(stream);
  598.  
  599. if(err1=fseek(stream,0,2) != 0) print("Fseek to end failed\n"); /* go to end of file */
  600. endfile=ftell(stream);
  601. seek=endfile-512; /* back up 512 */
  602. endoffile=FALSE;
  603. toget=512; /* start out getting 512 characters */
  604.  
  605. while(!endoffile) {
  606.  
  607.     if (seek < 0) {
  608.         toget=512+seek; /* get the difference in characters, seek is negative */
  609.         seek=0;
  610.         }
  611.  
  612.     if (seek==0) endoffile=TRUE;
  613.  
  614.     if(err1=fseek(stream,seek,0) != 0) print("Fseek failed\n");
  615.  
  616.     got=fread(&temp[0],1,toget,stream);
  617.  
  618.     temp[got]='\0'; /* remember! the string starts at 0, got it end +1 */
  619.  
  620.     if (got < 512) endoffile=TRUE;
  621.     if (got == 0) break;
  622.  
  623.     strstart= (strlen(temp) -1); /* find the end of it */
  624.  
  625.     strend=strstart;
  626.  
  627.  
  628.     while (strend > 0) {
  629.  
  630.          do { 
  631.             strend--;
  632.             } while (temp[strend] != 0x0A && strend >0) ;/* go to the start of line */
  633.  
  634.         i=0;
  635.         if (strend == 0) count= 0;
  636.         else count=strend +1;
  637.  
  638.         while (count <= strstart){ /* copy the string over */
  639.             output[i]=temp[count];
  640.             i++;
  641.             count++;
  642.             }
  643.         output[i]='\0';
  644.  
  645.         strstart=strend;
  646.  
  647.         if (strend == 0 && !endoffile) {
  648.             strcpy (nexttime,output); /* save the line for next time */
  649.             }
  650.         else {    
  651.             strcat(output,nexttime); /* add in any from last time */
  652.             a=0;
  653.             while (output[a] != '\0') {
  654.                 if (G->okcancel[u]) {if (G->cancel[u]) break;} /* check for cancel press */
  655.                 if ((output[a] == 0x0A) || (output[a] == 0x0D)) { send(G->CR[u]); }
  656.                 else G->out(output[a]);
  657.                 ++a;
  658.                 }
  659.             strcpy (nexttime,""); /* we used it so blank it out */
  660.             }
  661.         }
  662.     seek=seek-512; /* back up 512 */
  663.  
  664.     }
  665. G->cont[u]=FALSE; /* set for term line counting */
  666. }
  667.  
  668.  
  669.